package o;

import android.content.Context;
import com.huawei.hms.api.ConnectionResult;
import com.huawei.hms.api.HuaweiApiAvailability;
import com.huawei.hms.api.HuaweiApiClient;
import com.huawei.hms.api.HuaweiApiClient.Builder;
import com.huawei.hms.api.HuaweiApiClient.ConnectionCallbacks;
import com.huawei.hms.api.HuaweiApiClient.OnConnectionFailedListener;
import com.huawei.hms.support.api.pay.HuaweiPay;

public abstract class eqj {
    private static HuaweiApiClient ˋ;

    static class c implements OnConnectionFailedListener {
        private eqr ˎ;

        public c(eqr o_eqr) {
            this.ˎ = o_eqr;
        }

        public void onConnectionFailed(ConnectionResult connectionResult) {
            Logger.ˋ("HiAppHmsConnectionManager", "initHwpayClient Connect fialed，ErrorCode：" + connectionResult.getErrorCode());
            if (HuaweiApiAvailability.getInstance().isUserResolvableError(connectionResult.getErrorCode())) {
                if (this.ˎ != null) {
                    this.ˎ.ˋ(connectionResult.getErrorCode());
                }
            } else if (this.ˎ != null) {
                this.ˎ.ॱ(connectionResult.getErrorCode());
            }
        }
    }

    public static class e implements ConnectionCallbacks {
        private HuaweiApiClient ˊ;
        private eqr ˎ;

        public e(eqr o_eqr, HuaweiApiClient huaweiApiClient) {
            this.ˎ = o_eqr;
            this.ˊ = huaweiApiClient;
        }

        public void onConnected() {
            Logger.ˎ("HiAppHmsConnectionManager", "initHwpayClient Connect Successed");
            if (this.ˎ != null) {
                this.ˎ.ॱ();
            }
        }

        public void onConnectionSuspended(int i) {
            Logger.ˎ("HiAppHmsConnectionManager", "initHwpayClient Connect Interrupted");
            if (this.ˎ != null) {
                this.ˎ.ॱ(i);
            }
            if (this.ˊ != null) {
                this.ˊ.connect(null);
            }
        }
    }

    public static HuaweiApiClient ˋ(eqr o_eqr) {
        if (ˋ == null) {
            Logger.ˎ("HiAppHmsConnectionManager", "Get hwpayClient is null , will init hwpayClient");
            ˎ(o_eqr);
        } else if (!ˋ.isConnected()) {
            ˋ.setConnectionCallbacks(new e(o_eqr, ˋ));
            ˋ.setConnectionFailedListener(new c(o_eqr));
            ˋ.connect(null);
        }
        return ˋ;
    }

    public static void ˎ() {
        if (ˋ != null) {
            ˋ.disconnect();
            ˋ = null;
        }
    }

    private static void ˎ(eqr o_eqr) {
        Context ˋ = ContentManager.getInstant().getContext();
        if (ˋ != null) {
            ˋ = new Builder(ˋ).addApi(HuaweiPay.PAY_API).addConnectionCallbacks(new e(o_eqr, ˋ)).addOnConnectionFailedListener(new c(o_eqr)).build();
            Logger.ˎ("HiAppHmsConnectionManager", "initHwpayClient init finish,will connect hmsClient");
            ˋ.connect(null);
        }
    }
}
